﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using QuanLiNhaSachDAO;
using QuanLiNhaSachDTO;

namespace QuanLiNhaSachBUS
{
    public class TheLoaiBUS
    {
        public static DataTable loadAll()
        {
            try
            {
                return TheLoaiDAO.selectAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi load");
            }
            return null;
        }

        public static void insert(TheLoai m)
        {
            try
            {
                TheLoaiDAO.insert(m);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi thêm");
            }
        }

        public static void update(TheLoai m)
        {
            try
            {
                TheLoaiDAO.update(m);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi chỉnh sửa");
            }
        }

        public static void delete(string id)
        {
            try
            {
                TheLoaiDAO.delete(id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi xóa");
            }
        }

        public static TheLoai search(string id)
        {
            try
            {
                TheLoai tl = new TheLoai();
                DataTable dt = TheLoaiDAO.search(id);
                tl.Id = dt.Rows[0]["id"].ToString();
                tl.Ten = dt.Rows[0]["Ten"].ToString();
                return tl;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi tìm kiếm");
            }
            return null;
        }

        public static DataTable TimSachTuTheLoai(string id)
        {
            try
            {
                return TheLoaiDAO.TimSachTuTheLoai(id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi tìm sách");
            }
            return null;
        }
    }
}
